<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 200px;
            height: 200px;
            background: red;
        }
        .active{
            color: white;
        }
    </style>
</head>
<body>
    A B C d
    <div class="box">111111</div>
    <button>点击添加类名</button>
    <button>点击删除类名</button>
    <button>查看是否包含某个类名</button>
    <script>
        // 点击document的时候 加上active类名
        // 一、操作className来操作类名；
        // var boxEle = document.querySelector(".box");
        // document.onclick = function(){
        //     boxEle.className += " active";
        // }

        // 二、操作类名对象；
            var boxEle = document.querySelector(".box");
            var btns = document.querySelectorAll("button");
            // 1.添加类名classList.add
            btns[0].onclick = function(){
                boxEle.classList.add("active");
            }
            // 2.删除类名 classList.remove();
            btns[1].onclick = function(){
                boxEle.classList.remove("active");
            }
            // 3.查看是否包含类名
            btns[2].onclick = function(){
              var res =   boxEle.classList.contains("active");
              console.log(res);
            }

            // 1.吃食物 2.
    </script>
</body>
</html>